package com.example.administrator.managesystem.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.base.BaseActivity;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

/**
 * Created by Administrator on 2018/12/12.
 */



public class ShareActivity extends BaseActivity{
    private TextView share;

    @Override
    protected void onCreate( @Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);
        share=findViewById(R.id.share);
        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url="http://www.gaoshouyou.com";
                UMImage thumb = new UMImage(ShareActivity.this,R.drawable.app_icon);
                UMWeb web = new UMWeb(url);
                web.setTitle("荒野行动高手攻略");//标题
                web.setThumb(thumb);  //缩略图
                new ShareAction(ShareActivity.this).withText("hello").setDisplayList(SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN).withMedia(web)
                        .setCallback(shareListener).open();
            }
        });



    }


    @Override
    public void initView() {

    }

    @Override
    public void doBusiness() {

    }

    @Override
    public int getLayoutId() {
        return 0;
    }


    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {
        }
        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(ShareActivity.this,"成功了",Toast.LENGTH_LONG).show();
        }
        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(ShareActivity.this,"失败"+t.getMessage(),Toast.LENGTH_LONG).show();
        }
        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(ShareActivity.this,"取消了",Toast.LENGTH_LONG).show();
        }
    };

}
